package com.info.zhiduoduo.repository.mapper.taxer;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.taxer.TaxerCompanyDto;
import com.info.zhiduoduo.repository.dto.taxer.TaxerCompanyListDto;
import com.info.zhiduoduo.repository.entity.taxer.TaxerCompany;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  收藏企业表 Mapper 接口
 * </p>
 *
 * @author bob
 * @since 2019-11-17
 */
public interface TaxerCompanyMapper extends BaseMapper<TaxerCompany> {

	@Select(" select * from zdd_taxer_company tc " +
			" where tc.userid = #{userid} " +
			" and tc.company_name like '%${name}%' " +
			" and tc.deleted = 0 " +
			" order by tc.companyid desc ")
	List<TaxerCompanyDto> getCompanyList(String name, int userid);

	// 后台查询 收藏列表 2021-03-01 修改  列表返回增加：创客工作室对应的交易企业、及企业对应的商务经理、创客目前的交易税费率
	/*@Select(" select tc.*  , " +
			" ( SELECT username FROM  zdd_maker_studio ms where ms.userid = tc.userid  ) as username , " +
			" ( SELECT realname FROM  zdd_maker_account ma where ma.userid = tc.userid ) as realname " +
			" from zdd_taxer_company tc " +
			" where 1 = 1  ${whereStr} " +
			" and tc.deleted = 0 " +
			" order by tc.createtime desc ")*/
	@Select(" SELECT tc.* , ms.username , ms.gen_low_service_rate , ms.gen_high_service_rate , ms.gen_high_tax_rate, " +
			" ms.spe_service_rate , ms.spe_tax_rate , ms.yearly_high_tax_rate , ms.yearly_high_service_rate , " +
			" ms.yearly_high_2_tax_rate , ms.yearly_high_2_service_rate , " +
			" ms.yearly_high_3_tax_rate , ms.yearly_high_3_service_rate , " +
			" ma.realname, m.maker_type, ms.taxer_gen_low_service_rate, " +
			" if(m.maker_type = 2 , '节税侠' , '纯代理' ) as makerTypeStr , " +
			" ( SELECT compname FROM zdd_company where compid = m.bindcompid ) as compname , " +
			" ( SELECT business_manager FROM zdd_business_manager bm where bm.business_manager_id = " +
			"    ( SELECT business_manager_id FROM zdd_company_account WHERE compid = m.bindcompid  ) " +
			" ) businessManager " +
			" from zdd_taxer_company tc " +
			" LEFT JOIN  zdd_maker_studio ms ON  ms.userid = tc.userid " +
			" LEFT JOIN zdd_maker_account ma ON  ma.userid = tc.userid " +
			" LEFT JOIN zdd_maker m ON m.userid = tc.userid " +
			" WHERE 1 = 1  and tc.deleted = 0 " +
			" ${whereStr} " +
			" order by tc.createtime desc ")
	List<TaxerCompanyListDto> queryCompanyList(@Param("whereStr") String whereStr);


	@Select(" select * from zdd_taxer_company tc " +
			" where tc.companyid = #{companyid} ")
	TaxerCompanyDto getCompanyInfo(int companyid);

	@Select(" select * from zdd_taxer_company " +
			" where userid=#{userid} and company_name=#{companyName} and creditcode=#{creditcode} ")
	List<TaxerCompany> getCompanyExit(@Param("userid") Integer userid,
								@Param("companyName")String companyName,
								@Param("creditcode")String creditcode);
}
